package gradingcalculator;

public class Item {
    
    //Attributes
    private String name = "None";
    private Instance[] instances;
    private int gradeScore;
    private int totalScore;
    private double weight;
    private int position = 0;
    
    //Constructor
    public Item(String name, double weight) {
        this.name = name;
        this.weight = weight;
    }
    
    
    //Returns
    public String getName(){
        return name;
    }
    public Instance[] getInstances(){
        return instances;
    }
    public Instance getInstance(int index){
        return instances[index];
    }
    public int getGradedScore(){
        return totalScore;
    }
    public int getTotalScore(){
        return totalScore;
    }
    public double getWeight(){
        return weight;
    }
    public int getPosition() {
        return position;
    }
    
    
    //Modifiers
    public void setName(String name){
        this.name = name;
    }
    public void setGradeScore(int gradeScore){
        this.gradeScore = gradeScore;
    }
    public void setTotalScore(int totalScore){
        this.totalScore = totalScore;
    }
    public void setWeight(double weight){
        this.weight = weight;
    }
    public void setPosition(int position){
        this.position = position;
    }
    
// ===== Advanced Modifiers (Adds, Counters, and Array Manipulators)============
    
    //ADDS
    public void addInstance(Instance instance){
        int length = this.instances.length;
        Instance[] proxy = new Instance[length+1];
        System.arraycopy(this.instances, 0, proxy, 0, length);
        proxy[length] = instance;
        this.instances = proxy;
    }
    public void removeInstance(Instance instance, int index){
        int length = this.instances.length;
        Instance[] proxy = new Instance[length-1];
        System.arraycopy(this.instances, 0, proxy, 0, index);
        System.arraycopy(this.instances, index, proxy, index, length-index);
        this.instances = proxy;
    }
    public void addInstance(double max){
        //Create an element in the array if the array is null
        if(instances == null) { instances = new Instance[1]; }
        //Otherwise add another element to the end of array
        else { expandInstancesBy(1); }
        //Create a Instance in the Grading Calculator named 'name parameter'
        instances[instances.length-1] = new Instance(max);
    }
    public void addInstance(double max, double grade){
        //Create an element in the array if the array is null
        if(instances == null) { instances = new Instance[1]; }
        //Otherwise add another element to the end of array
        else { expandInstancesBy(1); }
        //Create a Instance in the Grading Calculator named 'name parameter'
        instances[instances.length-1] = new Instance(max, grade);
    }
    //ARRAY MANIPULATOR
    private void expandInstancesBy(int i) {
        Instance[] proxy = new Instance[instances.length+i];
        System.arraycopy(instances, 0, proxy, 0, instances.length);
        instances = proxy;
    }
}
